package com.vrsys.task.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.vrsys.domain.IDfromTable;
import com.vrsys.persistence.IDfromTableMapper;
import com.vrsys.util.IDGenerator;

@Service("idPreCheckService")
public class IDpreCheckService {
    @Autowired
    private IDfromTableMapper idFromTableMapper;
    @Autowired
    private IDGenerator idGenerator;

    public void validateIds(String idStorePropertiesFile) throws Exception {
        IDfromTable idt = idFromTableMapper.queryIds();
        idGenerator.setIdStorePropertiesFile(idStorePropertiesFile);
        if(null != idt) {
            if(idt.getOrderId() != idGenerator.getOrderId())
                idGenerator.setOrderId(idt.getOrderId());
            if(idt.getLineId() != idGenerator.getLineId())
                idGenerator.setLineId(idt.getLineId());
            if(idt.getProductId() != idt.getProductId())
                idGenerator.setProductId(idt.getProductId());
            if(idt.getCoupon4UserId() != idGenerator.getCoupon4UserId())
                idGenerator.setCoupon4UserId(idt.getCoupon4UserId());
        }
    }

//    @Transactional(isolation=Isolation.READ_COMMITTED, rollbackFor=Throwable.class)
}
